package com.ny.controller;

import com.ny.entity.Result;
import com.ny.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ny.service.UserService;
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/selectALLUser")
    public Result selectALLUser(){
        return Result.success(userService.findALLUser());
    }

    @PostMapping("/login")
    public Result fingUser(String username, String password){
        return Result.success(userService.login(username,password));
    }
    @GetMapping("/findUserByUsername")
    public Result findUserByUsername (String username){
        User user=userService.fingUserByUsername(username);
        System.out.println(user);
        if (username != null && user !=null ){
            return Result.success(user);
        }
        return Result.notFound("用户名不存在");
    }
// 注册

    //网址：http://localhost:8081/registerUser
    @PostMapping("/registerUser")
    public Result registerUser(User user){
        int result=userService.registerUser(user);

        return Result.success("注册成功");
    }
    //邮箱存在

    @GetMapping("/findUserByEmail")
    public Result findUserByEmail(String email){
        User user=userService.findUserByEmail(email);
        if (user != null){
            return Result.success("邮箱已存在");

        }
        return Result.success("邮箱不存在");

    }
    //发送验证码
    //网址：http://localhost:8081/sendEmailCode?email=<EMAIL>
   /* @GetMapping("/findUserByEmail")
    public Result findUserByEmail(String email){
        User user=userService.findUserByEmail(email);
        if (user == null){
        return Result.notFound("邮箱不存在");
        }
        return Result.success("发送成功");
    }
*/









}
